package com.rpay.web.controller;

import com.rpay.common.dto.user.UserDTO;
import com.rpay.common.enums.PcsResultCode;
import com.rpay.common.util.StringUtil;
import com.rpay.common.vo.PcsResult;
import com.rpay.service.config.ServiceThreadLocal;
import com.rpay.service.user.IUserService;
import com.rpay.service.util.SpringUtil;
import org.springframework.beans.factory.annotation.Value;

/**
 * Title：
 * Description
 *
 * @author fxg06 on 2018/5/4
 * @version 1.0
 */
public class BaseController {

    protected PcsResult newResult() {
        return new PcsResult(PcsResultCode.SUCCESS);
    }

    /**
     * 构建 分页 页数
     *
     * @param pageIndex 页
     * @return int
     */
    protected int getPageIndex(Integer pageIndex) {
        return (pageIndex == null || pageIndex < 1) ? 1 : pageIndex;
    }

    /**
     * 构建 分页 每页显示条数
     *
     * @param pageSize 每页显示条数
     * @return int
     */
    protected int getPageSize(Integer pageSize) {
        if (pageSize == null || pageSize < 1) {
            return 10;
        }
        if (pageSize > 50) {
            return 50;
        }
        return pageSize;
    }

    protected Integer getUserId() {
        return ServiceThreadLocal.getUserId();
    }

    protected UserDTO getUser() {
        IUserService userService = SpringUtil.getBean(IUserService.class);
        UserDTO userDTO = userService.getUserById(ServiceThreadLocal.getUserId());
        return userDTO;
    }
}
